package ch01;

public class AppleTree {
    private String name = "苹果树";               // 名称
    private String brand;                        // 品种
    private int growTime = 10;                   // 成长期
    private int harvestTime = 2;                 // 采摘期
    private int numsOfFruits = 100;              // 果实数量
    private String status = "生长期";             // 生长状态
    private boolean isHarvested = false;         // 是否采摘

    /**
     * 默认构造器 如果我们不写任何构造器 系统会自动添加默认构造器
     * 只是负责内存分配 没有完成属性赋值
     */
    public AppleTree() {
        this("金帅");
    }

    /**
     * 带参构造器
     * @param brand  传入指定的品种数据
     */
    public AppleTree(String brand) {
        this.brand = brand;
    }

    /**
     *
     * @param name
     * @param brand
     * @param growTime
     * @param harvestTime
     * @param numsOfFruits
     */
    public AppleTree(String name, String brand, int growTime, int harvestTime, int numsOfFruits) {
        this(brand);
        this.name = name;
        this.growTime = growTime;
        this.harvestTime = harvestTime;
        this.numsOfFruits = numsOfFruits;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public int getGrowTime() {
        return growTime;
    }

    public void setGrowTime(int growTime) {
        this.growTime = growTime;
    }

    public int getHarvestTime() {
        return harvestTime;
    }

    public void setHarvestTime(int harvestTime) {
        this.harvestTime = harvestTime;
    }

    public int getNumsOfFruits() {
        return numsOfFruits;
    }

    public void setNumsOfFruits(int numsOfFruits) {
        this.numsOfFruits = numsOfFruits;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public boolean isHarvested() {
        return isHarvested;
    }

    public void setHarvested(boolean harvested) {
        isHarvested = harvested;
    }

    /**
     * 输出苹果树特性
     */
    public void print(){
        System.out.println("******作物特性******");
        System.out.println("您种植了"+this.name+"。");
        System.out.println("成长期"+this.growTime+"天，"
                +"采摘期"+this.harvestTime+"天，"
                +"果实数量为"+this.numsOfFruits+"，现在处于"+this.status+"。");
        System.out.println(this.name+"属于水果作物，品种："+this.brand+"。");
    }

    /**
     * 生长报告
     * @param day 生长的天数
     */
    public void printGrowReport(int day){
        if (day<this.growTime){
            this.status = "成长期";
            System.out.println("******"+this.name+"生长报告（"+this.status+"）******");
            System.out.println("您种植了"+this.name+"，品种："+this.brand+"。");
            System.out.println(this.name+"处于"+this.status);
            System.out.println("已生长"+day+"天，距离收获果实还有"+(this.growTime-day)+"天。");
        }else if(day<this.growTime+this.harvestTime){
            this.status = "采摘期";
            System.out.println("******"+this.name+"生长报告（"+this.status+"）******");
            System.out.println("您种植了"+this.name+"，品种："+this.brand+"。");
            System.out.println(this.name+"处于"+this.status);
            if (!this.isHarvested()){
                System.out.println("果实已成熟，请尽快采摘！");
            }else{
                System.out.println("果实已成熟并已采摘完毕！");
            }
        }else{
            this.status = "已死亡";
            System.out.println("******"+this.name+"生长报告（"+this.status+"）******");
            System.out.println("您种植了"+this.name+"，品种："+this.brand+"。");
            System.out.println(this.name+this.status+"，请尽快清理土地！");
        }
    }

    /**
     * 采摘
     */
    public void harvest(){
        System.out.println("******"+this.name+"收获果实（"+this.status+"）******");
        if (this.status == "采摘期"){
            if (!this.isHarvested()){
                System.out.println("收获果实"+this.numsOfFruits+"个！");
                this.setHarvested(true);
            }else{
                System.out.println("果实已采摘！");
            }
        }else{
            System.out.println("抱歉！目前没有果实可以采摘！");
        }
    }
}
